﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加用户信息</title>
    <link href="${pageContext.request.contextPath}/css/houtaimain.css" rel="stylesheet" type="text/css" />

</head>


<h1 class="h1_style"><i class="i_h1"></i>添加用户信息</h1>
<div class="div_left">


        <p class="form_p"><label class="form_label">学号：</label><input type="text" name="username" id="username" class="form_input readonly " minlength="2"  required ><i class="i_start"></i> <a class="a_note">必填，密码会在后端自动生成</a> </p>
    <div class="clear"></div>
</div>

<input type="button" value="保存" class="but_save" onclick="requestJson()"/>
</p>



<script src="${pageContext.request.contextPath}/js/date/js/laydate.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    function requestJson(){

        var username =$("#username").val();//#是id选择器

        if(username==""){
            alert("学号不能为空！");
            return false;
        }


        if(!username.match(/\d{9}$/)){
            alert("请输入正确的学号！");
            return false;
        }
        else
        {
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath}/user/addUser',
                dataType:"json",//注意使用的是打他dataType，而不是Content-Type
                async: true,
                data:{username:username},
                success:function(data){
                    if(data==0){
                         alert("添加成功！")
                        window.location.href ="${pageContext.request.contextPath}/user/query";
                    }
                    else if (data==1){
                        alert("该用户已存在！")

                    }else if (data==-500) {
                        alert("服务器出现故障，请稍后再试！")
                    }
                }
            });
        }
    }
</script>
</body>
</html>
